// 模型
import Model from "@/views/threeDimensional/mode/model";
import * as THREE from "three";

export function loadCity(scene: any) {
  // const mesh = model.lodeModel("/mode/BinDunDun.FBX",[0,0,0]);
  // const sprite = model.sprite([0, 60, 4], [50, 50]);
  // sprite.visible = false;
  // mesh.add(sprite);
  // // 单击事件
  // mesh.onClick = () => {
  //   console.log("单击事件");
  //   sprite.visible = true;
  // };

  const model = new Model(scene);

  // 城市构建
  const sprite1 = model.sprite([0, 40, 0]);

  // 加载城市模型
  const sprit: any = new THREE.TextureLoader().load("/img/WechatIMG121.jpeg");

  // 贴图大小
  sprit.center.set(0.5, 0.5);
  let i = 1;
  setInterval(() => {
    i = i - 0.015;
    if (i < 0) {
      i = 1;
    }
    sprit.repeat.set(i, i);
  }, 25);
  const plane: any = new THREE.MeshPhongMaterial({
    map: sprit,
    color: "#2487af",
    wireframe: false,
  });
  const material = new THREE.MeshBasicMaterial({color: "#2eb4ea"});

  // 移动的人行道
  const sprit1: any = new THREE.TextureLoader().load("/img/move.png");
  // 贴图重复
  sprit1.wrapS = THREE.RepeatWrapping;
  sprit1.wrapT = THREE.RepeatWrapping;
  // 贴图大小
  sprit1.repeat.set(1, 12);
  sprit1.center.set(0.2, 0.2);
  let num: number = 0.1;
  setInterval(function () {
    num += 0.05;
    // 贴图偏移
    sprit1.offset = new THREE.Vector2(0, num);
  }, 50);
  const material1 = new THREE.MeshBasicMaterial({
    map: sprit1,
    alphaTest: 0.5,
    side: THREE.DoubleSide,
    color: "#7e8eff",
  });

  // 透明色
  const material3 = new THREE.MeshBasicMaterial({
    map: sprit1,
    alphaTest: 0.5,
    side: THREE.DoubleSide,
    color: "#7e8eff",
    opacity: 0,
  });

  // 光柱
  const sprit2: any = new THREE.TextureLoader().load("/img/guang.png");
  const material2 = new THREE.MeshBasicMaterial({
    map: sprit2,
    side: THREE.DoubleSide,
    //blending: THREE.AdditiveBlending,
    transparent: true,
    opacity: 0.3
  });

  // 飞艇外观颜色
  const airship: any = new THREE.MeshPhongMaterial({
    color: "#e5ceac",
    wireframe: false,
  });
  // 黑色
  const black: any = new THREE.MeshPhongMaterial({
    color: "#8f96cc",
    wireframe: false,
  });

  const obj2 = model.animationModel(
    "/mode/feiting.FBX",
    [-20, 40, -100],
    [0.15, 0.15, 0.15],
    [airship, airship, material1, material3, black]
  );
  obj2.add(sprite1.clone())

  const obj3 = model.animationModel(
    "/mode/feiting.FBX",
    [200, 140, 100],
    [0.2, 0.2, 0.2],
    [airship, airship, material1, material3, black]
  );
  obj3.add(sprite1.clone())

  // 管道
  model.lineObj()

  model.lodeModel("/mode/chengshi.FBX", [-100, -30, 0], [0.02, 0.02, 0.02], [plane, material, material1, material2]);
}
